<!DOCTYPE html>
<html>

<head>
    <meta http-equiv="Content-Type" content="text/html;charset=utf-8">
</head>

<body>

    <div id="container" style="width:100%;height:600px;padding: 0px;border:0px solid grey"></div>

    <script src="monaco-editor/min/vs/loader.js"></script>
    <script src="./xml-editor.js"></script>
    <script>
        require.config({ paths: { 'vs': 'monaco-editor/min/vs' } });
        require(['vs/editor/editor.main'], function () {
            var editor = monaco.editor.create(document.getElementById('container'), {
                value: null,
                language: 'xml',
                theme: "vs-dark",
                quickSuggestions:false
            });
            window.editor = editor;
            document.getElementById("container").style.height = document.documentElement.clientHeight + "px";
            editor.layout();
            monaco.languages.registerCompletionItemProvider("xml",new XmlEditorContent());
            editor.onDidChangeModelContent(function(){
                if(window.onCodeChange != null)
                    window.onCodeChange();
            });
        });
        //注册项目缓存
        window.registerZProjectData = function(data){
            XmlEditorContent.registerZProjectData(data);
        }
        //注册提示工具
        window.registerCompletionItemProvider = function (item) {
            monaco.languages.registerCompletionItemProvider(item);
        }
        //自适应宽度
        window.onresize = function () {
            if (editor) {
                document.getElementById("container").style.height = document.documentElement.clientHeight + "px";
                editor.layout();
            }
        };
        window.getCodeValue = function () {
            return editor.getValue();
        }
        window.setCodeValue = function (data){
            editor.setValue(data);
        }
    </script>
</body>

</html>